package com.jdd.modules.deviceLog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jdd.common.util.LoginUserUtils;
import com.jdd.modules.deviceLog.entity.TUserCmdLog;
import com.jdd.modules.deviceLog.mapper.TUserCmdLogMapper;
import com.jdd.modules.deviceLog.service.ITUserCmdLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdd.modules.userOptionLog.entity.TUserOptionLog;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2022-10-20
 */
@Service
public class TUserCmdLogServiceImpl extends ServiceImpl<TUserCmdLogMapper, TUserCmdLog> implements ITUserCmdLogService {

    @Resource
    public TUserCmdLogMapper tUserCmdLogMapper;


    @Override
    public List<TUserCmdLog> selectDeviceByUserId(String userId) {
        LambdaQueryWrapper<TUserCmdLog> logLambdaQueryWrapper = new LambdaQueryWrapper<>();
        logLambdaQueryWrapper.eq(TUserCmdLog::getUserId,userId);
        List<TUserCmdLog> list = this.list(logLambdaQueryWrapper);
        return list;
    }

    @Override
    public void setOptionStatus(String userId, int status) {
        LambdaUpdateWrapper<TUserCmdLog> logLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        logLambdaUpdateWrapper.eq(TUserCmdLog::getUserId,userId);
        logLambdaUpdateWrapper.set(TUserCmdLog::getOptionStatus,status);
        this.update(logLambdaUpdateWrapper);
    }

    @Override
    public IPage<TUserOptionLog> findList(Page<TUserOptionLog> page, TUserOptionLog tUserOptionLog) {
        List<String> projectList = LoginUserUtils.getProjectCodeList();
        IPage<TUserOptionLog> iPage =  tUserCmdLogMapper.findList(page,tUserOptionLog,projectList);
        return iPage;
    }
}
